package com.jfshop.framework.util;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 
 * Name: ExecutorServiceUtil.java
 * ProjectName: [Framework-Base]
 * Package: [com.grandthink.framework.util.ExecutorServiceUtil.java]
 * Description: 多线程, 线程池  ExecutorService 工具类
 * 
 * @since JDK1.6
 * @see
 * @version [v1.0]
 *
 * Author: @author: Thunder
 * Date: 2013年12月5日 上午9:35:17
 *
 * Update-User: @author
 * Update-Time:
 * Update-Remark:
 * 
 * Check-User:
 * Check-Time:
 * Check-Remark:
 * 
 * Company: GrandThink
 * Copyright: GrandThink
 */
public final class ExecutorServiceUtil {
	
	private ExecutorServiceUtil() {
		throw new RuntimeException();
	}
	
	public static ExecutorService createExecutor(int threadPoolSize) {
		BlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>();
		ThreadFactory threadFactory = new ThreadFactory() {
			
			@Override
			public Thread newThread(Runnable r) {
				Thread t = new Thread(r);
				t.setPriority(Thread.NORM_PRIORITY);
				return t;
			}
		};
		return new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 
				0L, TimeUnit.MILLISECONDS, taskQueue, threadFactory);
	}

}
